package server

import (
	"github.com/gin-gonic/gin"
	"monitoring-api/api"
	"monitoring-api/middleware"
)

// NewRouter 路由配置
func NewRouter() *gin.Engine {
	r := gin.Default()
	gin.SetMode(gin.ReleaseMode)
	// 中间件, 顺序不能改
	r.Use(middleware.Cors())

	// 路由
	v1 := r.Group("/api/v1")
	{
		v1.POST("/ping", api.Ping)

		// 用户登录
		v1.POST("user/register", api.UserRegister)

		// 用户登录
		v1.POST("user/login", api.UserLogin)

		// 需要登录保护的
		auth := v1.Group("")
		auth.Use(middleware.AuthRequired())
		{
			auth.GET("/user/info", api.UserInfo)
			//网站管理
			auth.POST("/web/add", api.AddWeb)
			auth.GET("/web/list", api.ListWeb)
			auth.PUT("/web/edit", api.UpdateWeb)
			auth.DELETE("/web/delete", api.DeleteWeb)
			//获取日志信息
			auth.POST("/logs/area", api.GetArea)
			auth.POST("/logs/browser", api.GetBrowser)
			auth.POST("/logs/err", api.GetErrorsLogs)
			auth.POST("/logs/beh", api.GetActionsLogs)
			auth.POST("/logs/per", api.GetPerLogs)
			auth.POST("/logs/http", api.GetReqLogs)
			//统计日志信息
			auth.POST("logs/stat", api.GetStatInfo)
			//获取所有图表数据
			auth.POST("logs/all", api.GetGraph)
		}
		// 上报异常信息
		v1.POST("/report/err", api.UploadErr)
		v1.POST("/report/per", api.UploadPer)
		v1.POST("/report/beh", api.UploadAction)
		v1.POST("/report/http", api.UploadReq)
	}
	return r
}
